package top.huhuiyu.ds;

import java.util.ArrayList;
import java.util.List;

public class MyListDemo {
  public static void main(String[] args) {
    // List可以记住add的次序，通过下标访问(可以理解为动态数组)
    List<String> list = new ArrayList<>();
    list.add("张三");
    list.add("孙笑川");
    list.add("李赣");
    System.out.println(list.get(1));
    list.add(1, "添加到一号位置");
    System.out.println(list.get(1));
    System.out.println("==============");
    for (int i = 0; i < list.size(); i++) {
      System.out.println(list.get(i));
    }
    System.out.println("=================");
    list.remove(0);
    for (int i = 0; i < list.size(); i++) {
      System.out.println(list.get(i));
    }
    System.out.println("自己实现的list===============");
    MyList<String>myList=new MyList<>();
    myList.add("孙笑川");
    myList.add("李赣");
    myList.add("娟妹");
    System.out.println(myList.get(1));
    myList.add(1,"添加到索引位置1");
    System.out.println(myList.get(1));
    System.out.println("========");
    for (int i = 0; i < myList.Size(); i++) {
      System.out.println(myList.get(i));
    }
    System.out.println("==========");
    myList.remove(1);
    for (int i = 0; i < myList.Size(); i++) {
      System.out.println(myList.get(i));
    }
  }
}
